#include <algorithm>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int cmp(int a,int b)
{
    return a>b;
}
int main() {
    int opnum = 0;
    cin >> opnum;
    cin.ignore();
    string op;
    vector<int> vec;
    while (getline(cin, op)) {
        string arg1,arg2,arg3;
        stringstream ss(op);
        getline(ss, arg1,' ');
        switch (arg1[0]) {
        case '1':
            getline(ss,arg2);
            vec.push_back(stoi(arg2));
            break;
        case '2':
            vec.pop_back();
            break;
        case '3':
            getline(ss,arg2);
            cout << vec[stoi(arg2)]<<endl;
            break;
        case '4':
            getline(ss,arg2,' ');
            getline(ss,arg3);
            vec.insert(vec.begin() + 1 + stoi(arg2), stoi(arg3));
            break;
        case '5':
            sort(vec.begin(), vec.end());
            break;
        case '6':
            sort(vec.begin(), vec.end(),cmp);
            break;
        case '7':
            cout<<vec.size()<<endl;
            break;
        case '8':
            for (auto e : vec) {
                cout<<e<<" ";
            }
            if (vec.size()!=0) {
                cout<<endl;
            }
            break;
        default:
            break;
        }
    }
}
// 64 位输出请用 printf("%lld")